<script>
    function getIndexOf(array, key) {
        let start = 0;
        let end = array.length-1;
        while(start<=end){
            let mid = parseInt((start+end)/2);
            if(array[mid]==key){
                return mid;
            }else if(key<array[mid]){
                end = mid -1;
            }else if(key>array[mid]){
                start = mid + 1;
            }
        }
        return -1;
    }
    array = [1,2,3,4,5,6,7,8,9]
    getIndexOf(array,4);
    // debugger


    // console.log(123);

</script>